package lib.bone.nepudata.domain.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lib.bone.common.converter.JpaListLongConverter;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Author : cg
 * @Date : 2022-1-13
 * 横向课题关联表
 */

@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "nepu_subject")
@EntityListeners(AuditingEntityListener.class)
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
@ApiModel("横向课题")
public class NepuSubject {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "横向课题ID",name = "id")
    String id;

    @ApiModelProperty("周期ID")
    @Column(name = "cycle_id")
    String cycleId;


    @ApiModelProperty(value = "横向课题经费",notes = "单位(万)")
    @Column(name = "funds",scale = 2)
    Double funds;

    /**
     * 对应课题ID 对应 nepu_subject_dict 中的 ID
     * 可以使用级联合 多对一 # 暂不使用
     */
    @ApiModelProperty(value = "对应课题类型ID",notes = "")
    @Column(name = "subject_dict_id")
    String subjectDictId;

    /**
     * 横向课题类型
     */
    @ApiModelProperty(value = "横向课题类型",notes = "自然科学，人文科学")
    @Column(name = "subject_type")
    String subjectType;

    /**
     * 横向课题名称
     */
    @ApiModelProperty(value = "横向课题名称",notes = "")
    @Column(name = "subject_name")
    String subjectName;

    /**
     * 横向课题负责人姓名
     */
    @ApiModelProperty(value = "横向课题负责人",notes = "")
    @Column(name = "leader")
    String leader;

    /**
     * 横向课题负责人ID
     */
    @ApiModelProperty(value = "横向课题负责人ID",notes = "")
    @Column(name = "leader_id")
    Long leaderId;

    /**
     * 课题编码
     */
    @ApiModelProperty("课题编码")
    @Column(name = "subject_code")
    String subjectCode;

    /**
     * 横向课题开始日期
     */
    @ApiModelProperty(value = "课题开始日期",notes = "课题开始日期，如2021/11/16")
    @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
    @Column(name = "start_date")
    Date startDate;

    /**
     * 纵向课题完成日期
     */
    @ApiModelProperty(value = "课题结束日期",notes = "课题结束日期，如2021/11/16")
    @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
    @Column(name = "end_date")
    Date endDate;

    /**
     * 横向课题成员ID列表
     */
    @ApiModelProperty(value = "横向课题成员ID列表",notes = "")
    @Convert(converter = JpaListLongConverter.class)
    @Column(name = "user_id_list")
    List<Long> userIdList;

    /**
     * 分配所得工作量
     */
    @ApiModelProperty(value = "工作量",notes = "")
    @Column(name = "workload",scale = 2)
    Double workload;


//    @ApiModelProperty(value = "工作量",notes = "")
//    @Column(name = "workload")
//    Integer workload;

    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;
    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        NepuTopic nepuTopic = (NepuTopic) o;
        return id != null && Objects.equals(id, nepuTopic.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}




